package com.example.demo.executor.sqlGenerate;

import com.example.demo.executor.backupDeal.BackupDataExecutor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class SqlGeneratorFactory {

    @Autowired
    private List<SqlGenerator> sqlGeneratorList;

    private Map<String,SqlGenerator> sqlGeneratorMap;

    @PostConstruct
    public void init(){
        sqlGeneratorMap = new HashMap<>();
        for(SqlGenerator generator : sqlGeneratorList){
            sqlGeneratorMap.put(generator.getDatabaseName(), generator);
        }
    }

    public SqlGenerator getSqlGenerator(String databaseName){
        return sqlGeneratorMap.get(databaseName);
    }
}
